package com.group3.group3.organ.control;
/**
 * Created with IntelliJ IDEA.
 *
 * @Author: Tom
 * @Date: 2022/05/19/16:33
 * @Description:
 */

import com.group3.group3.common.control.BaseController;
import com.group3.group3.mybatis.flexigrid.PadingRstType;
import com.group3.group3.mybatis.flexigrid.PagingBean;
import com.group3.group3.mybatis.ztree.ZtreeEntity;
import com.group3.group3.organ.entity.OrganEntity;
import com.group3.group3.organ.service.OrganService;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Controller
@RequestMapping("/organinfo")
public class OrganController extends BaseController {
    @Resource
    private OrganService organService;

    @Resource
    private MessageSource messageSource;

    @RequestMapping("/page")
    public String userPage(){
        return "organ/organPage";
    }

    @RequestMapping("/select")
    @ResponseBody
    public PadingRstType<OrganEntity> select(PagingBean paging){
        PadingRstType<OrganEntity> padingRstType=organService.select(paging);
        return padingRstType;
    }

    @RequestMapping("/selectById")
    @ResponseBody
    public OrganEntity selectById(String organUuid){
        return organService.selectById(organUuid);
    }

    @RequestMapping("/insert")
    @ResponseBody
    public String insert(String organName, String modifierid, String description){
        String organUuid= UUID.randomUUID().toString();
        Date date = new Date();
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
        String modtime=dateFormat.format(date);
        organService.insert(organUuid,organName,modifierid,modtime,description);
        return getSuccessMessag("organ.insert.success");
    }

    @RequestMapping("/delete")
    @ResponseBody
    public String delete(@RequestParam("organUuid") String organUuid){
        organService.delete(organUuid);
        return getSuccessMessag("organ.delete.success");
    }

    @RequestMapping("/update")
    @ResponseBody
    public String update(String organName, String description,String organUuid){
        organService.update(organName,description,organUuid);
        return getSuccessMessag("organ.update.success");
    }

    @RequestMapping("/selectParent")
    @ResponseBody
    public List<OrganEntity> selectParent(){
        return organService.selectParent();
    }


    @RequestMapping("/ListById")
    @ResponseBody
    public List<ZtreeEntity> zTreeList(String organUuid){
        List<ZtreeEntity> list = organService.zTreeList(organUuid);
        return list;
    }

    @RequestMapping("/updateById")
    @ResponseBody
    public String saveMenuByRoleId(String organUuid,String parentUuids){
        organService.updateById(organUuid,parentUuids);
        return getSuccessMessag("organ.menu.allocate.success");
    }
}

